package org.opens.mybatisplus.service.impl;

import org.opens.mybatisplus.service.AudioService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@Service(value = "audioService")
public class AudioServiceImpl implements AudioService {

    @Value("${audio.local-path}")
    private String localPath;

    @Override
    public InputStream getInputStreamFromLocalByFileName(String fileName) {
        File file = new File(localPath, fileName);
        System.out.println(file.getAbsoluteFile());
        if (!file.exists()) {
            return null;
        }
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
        return fileInputStream;
    }
}
